<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <title>Title</title>

    <!-- 引入 ECharts 文件 -->
    <script src="/echarts.min.js"></script>

    <script src="/jquery.min.js"></script>
</head>
<body>
    <p style="text-align: center" th:text="'Hello, ' + ${name} + '!'"/>
    <!-- 为 ECharts 准备一个具备大小（宽高）的Dom -->
    <div id="main" style="width: 1200px;height:500px; text-align: center"></div>
    <script type="text/javascript">
        $(function () {
            // 基于准备好的dom，初始化echarts实例
            var myChart = echarts.init(document.getElementById('main'));

            init(myChart);
        });

        function init(chart) {
            $.ajax({
                method : 'get',
                url : '/init',
                success : function (data) {
                    console.log(data);
                    // 指定图表的配置项和数据
                    option = {
                        tooltip: {
                            trigger: 'axis',
                            position: function (pt) {
                                return [pt[0], '10%'];
                            }
                        },
                        title: {
                            left: 'center',
                            text: '大数据量折线图',
                        },
                        legend: {
                            top: 'bottom',
                            data:['意向']
                        },
                        toolbox: {
                            show: true,
                            feature: {
                                dataView: {show: true, readOnly: false},
                                magicType: {show: true, type: ['line', 'bar', 'stack', 'tiled']},
                                restore: {show: true},
                                saveAsImage: {show: true}
                            }
                        },
                        xAxis: {
                            type: 'category',
                            boundaryGap: false,
                            data: data.category,
                            scale: true,
                            axisLine: {onZero: false}
                        },
                        yAxis: {
                            type: 'value',
                            boundaryGap: [0, '100%'],
                            minInterval: 0.01,
                            min: 15,
                            max: 15.4
                        },
                        dataZoom: [{
                            type: 'inside',
                            start: 0,
                            end: 100
                        }, {
                            start: 0,
                            end: 100
                        }],
                        series: [
                            {
                                name:'模拟数据',
                                type:'line',
                                smooth:true,
                                symbol: 'none',
                                sampling: 'average',
                                itemStyle: {
                                    normal: {
                                        color: 'rgb(255, 70, 131)'
                                    }
                                },
                                areaStyle: {
                                    normal: {
                                        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                            offset: 0,
                                            color: 'rgb(255, 158, 68)'
                                        }, {
                                            offset: 1,
                                            color: 'rgb(255, 70, 131)'
                                        }])
                                    }
                                },
                                data: data.data
                            }
                        ]
                    };

                    // 使用刚指定的配置项和数据显示图表。
                    chart.setOption(option);
                }
            });
        }
    </script>
</body>
</html>